/**
 * 合同订单 信息查询
 * @author mengyb
 * @date 2019/12/10
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        layui = win.layui,
        table,
        element,
        vueData = {

        },
        table_where = {

        },
        cols = [[
              {type: 'checkbox', title: '选择', fixed: 'left'}
            , {field: 'ROW_ID', width: 60, title: '序号', fixed: 'left'}
            , {field: 'GWCA005', width: 150, title: '合同编号', fixed: 'left', sort: true,
                search: 'default',searchOpts: {icon:true,readonly:true}}
            , {field: 'GWCA036', width: 120, title: '合同签订时间', sort: true,
                search: 'default',searchOpts: {type: 'daterange'}}
            , {field: 'GWCA002', width: 80, title: '订单类型',sort: true,filterDatas:app.datas_('crm_gwci001_gwca002'),
                search: 'default',searchOpts: {type:'select'}}
            , {field: 'GWCA001_NAME', width: 80, title: '销售地区',sort: true}
            , {field: 'GWCAORIG_NAME', width: 100, title: '部门',sort: true}
            , {field: 'GWCAORIU_NAME', width: 100, title: '业务员',sort: true}
            , {field: 'GWCAMLEGAL_NAME', width: 100, title: '签订单位',sort: true}
            , {field: 'GWCA006_NAME', width: 100, title: '客户单位',
                search: 'default', searchOpts: {icon:true,readonly:true}}
            , {field: 'GWAM004_NAME', width: 80, title: '车辆类型'}
            , {field: 'GWCB004', width: 80, title: '配置情况',filterDatas:app.datas_('crm_gwci001_gwcb004')}
            , {field: 'GWCB002', width: 80, title: '产品编号',
                search: 'default', searchOpts: {icon:true,readonly:true}}
            , {field: 'GWCB005_NAME', width: 80, title: '单位'}
            , {field: 'GWCB006', width: 80, title: '数量'}
            , {field: 'GWCB008', width: 80, title: '单价'}
            , {field: 'GWCB010', width: 80, title: '总价'}
            , {field: 'GWCA026', width: 120, title: '交货日期'}
            , {field: 'GWCA058', width: 120, title: '合同下单日期'}
            , {field: 'GWCB013', width: 120, title: '车辆配置明细'}
            , {field: 'GWCA007', width: 80, title: '最终用户'}
            , {field: 'GWCAADDR', width: 150, title: '设备使用地点'}
            , {field: 'GWCA024', width: 120, title: '质保期（月）'}
            , {field: 'GWCA025', width: 80, title: '付款周期',filterDatas:app.datas_('crm_gwci001_gwca025')}
            , {field: 'GWCA022', width: 120, title: '首付款支付时间'}
            , {field: 'GWCA021', width: 100, title: '首付款比例',filterDatas:app.datas_('crm_gwci001_gwca021')}
            , {field: 'GWCA020', width: 100, title: '支付方式',filterDatas:app.datas_('crm_gwci001_gwca020')}
            , {field: 'GWCA037', width: 80, title: '归档时间'}
            , {field: 'GWCA017', width: 80, title: '客户负责人'}
            , {field: 'GWCA018', width: 120, title: '联系方式'}
            , {field: 'XMDK001', width: 120, title: '实际交货日期'}
            , {field: 'GWCA039', width: 120, title: '中标通知书份数'}
            , {field: 'GWCA038', width: 120, title: '合同归档份数'}
            , {field: 'XMDD014', width: 120, title: '已发车辆（辆）'}
            , {field: 'XMDD014_ELSE', width: 120, title: '未发车辆（辆）'}
            /*, {
                width: 60,
                title: '',
                toolbar: '#script-gwcq001setting',
                fixed: 'right',
                align: 'center',
                unresize: true
            }*/
        ]],
        // gwcq001SettingAction,
        moduleName = '合同订单信息查询'
    ;

    var gwcq001 = app.Module.extend({
        init: function () {
            self = this;
            var _searchsArr = app.cloneJSON(cols[0]);
            self._super({
                _tag: 'gwcq001',
                _searchs: [{
                    id: 'gwcq001', tableId: 'gwcq001_table', datas: _searchsArr.pushArray([
                        {field: 'GWCAORIG', width: 80, title: '部门',search: 'default',searchOpts: {icon: true,readonly:true}},
                        {field: 'GWCAORIU', width: 80, title: '业务员',search: 'default',searchOpts: {icon:true,readonly:true}},
                        {field: 'GWCA006', width: 80, title: '客户单位',search: 'default', searchOpts: {icon:true,readonly:true}}
                    ])
                }],
                _loadTplsFull: [
                    {dom: 'common_open_window', tpl: 'common/_open_window'}
                ]
            }, win);
        },
        initTable: function () {
            // var sort = {"field":"GWCQDOCNO","sort":"desc"};
            // table_where['_SORT'] = JSON.stringify(sort);
            layui.use(['table'], function () {
                table = layui.table;
                table.render({
                    elem: app.getByid(doc, 'gwcq001_table'),
                    url: g_ctxPath + 'crm/gwcq001/getList',
                    exportsUrl: g_ctxPath + 'crm/gwcq001/exportsData',
                    exportsName: moduleName + '数据',
                    title: moduleName + '表',
                    id: 'gwcq001_table',
                    toolbar: '#table-toolbar',
                    defaultToolbar: ['filter', 'exports'],
                    height: 'full',
                    cols: cols,
                    loading: false,
                    page: true,
                    where: table_where,
                    done: function (res, curr, count) {

                    }
                });

                // layui.laytpl(app.getByid(doc, 'script-gwcq001setting-action').innerHTML).render({}, function (string) {
                //     gwcq001SettingAction = string;
                // });

                // var tipsIndex = null;

                // table.on('tool(gwcq001_table)', function (obj) {
                //     console.log(obj.data);
                //
                //     layer.tips(gwcq001SettingAction, obj.td, {
                //         tips: [3, '']
                //         , time: 3000
                //         , anim: 500
                //         , maxWidth: 120
                //         , skin: 'layui-table-tips'
                //         , success: function (layero, index) {
                //             tipsIndex = index;
                //             layero.find('li').on('click', function () {
                //                 switch ($(this).attr('inx')) {
                //                     case '1':
                //                         self._openTplFull({
                //                             tag: 'gwai700_edit',
                //                             tagData: {
                //                                 obj : obj,
                //                                 moduleName : moduleName
                //                             },
                //                             index: 0,
                //                             openOpts: {
                //                                 title: moduleName + '编辑'
                //                             }
                //                         });
                //                         break;
                //                     case '2':
                //                         app.confirm({
                //                             msg: '是否删除选择的数据？',
                //                             ok: function () {
                //                                 self.deleteData(obj);
                //                             }
                //                         });
                //                         break;
                //                 }
                //                 layer.close(index);
                //                 tipsIndex = null;
                //             });
                //         }
                //     });
                //     return false;
                // });

                //监听行双击事件
                // table.on('rowDouble(gwcq001_table)', function (obj) {
                //     self._openTplFull({
                //         tag: 'gwai700_edit',
                //         moduleName : moduleName,
                //         tagData: {
                //             is_check: true,
                //             obj : obj,
                //             moduleName : moduleName,
                //             is_show: true
                //         },
                //         index: 0,
                //         openOpts: {
                //             title: moduleName + '编辑'
                //         }
                //     });
                // });

                //监听事件
                // table.on('toolbar(gwcq001_table)', function (obj) {
                //     switch (obj.event) {
                //         case 'add':
                //             self._openTplFull({
                //                 tag: 'gwai700_edit',
                //                 tagData: {
                //                     is_add : true,
                //                     moduleName : moduleName
                //                 },
                //                 index: 0,
                //                 openOpts: {
                //                     title: moduleName + '编辑'
                //                 }
                //             });
                //             break;
                //         case 'del':
                //             app.confirm({
                //                 msg: '是否删除选择的数据？',
                //                 ok: function () {
                //                     self.deleteDataBatch();
                //                 }
                //             });
                //             break;
                //         case 'transformOrder':
                //             self.transformOrder();
                //             break;
                //     }
                // });

                // $(doc).on('click', function () {
                //     tipsIndex && layer.close(tipsIndex);
                // });

            });
        },
        reloadTableCurr: function () {
            self._reloadTable({id: 'gwcq001_table', where: table_where});
        },
        _ready: function () {
            vueData.serchData = table_where;
            this._super({
                vue: [{
                    el: '#page',
                    id: 'page',
                    data: vueData,
                    searchId: 'gwcq001',
                    methods: {
                        handleIconClick: function(field){
                            var vue = this;
                            if(field == 'GWCB002'){//产品开窗
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method:'q_gwam001',
                                            columnList: [
                                                {label: '产品编号', prop: 'GWAM001', width: '150'},
                                                {label: '说明', prop: 'GWAML003', width: '150'},
                                                {label: '助记码', prop: 'GWAML004', width: '150'}
                                            ],
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCB002 = data.GWAM001
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择产品编号',
                                        area: ['600px', '465px']
                                    }
                                });
                            }else if(field == 'GWCA006'){//客户单位开窗
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config:{
                                            method:'q_gwak001',
                                            columnList:[
                                                {label:'客户编号',prop:'GWAK001', width: 150},
                                                {label:'客户简称',prop:'GWAKL003', width: 150},
                                                {label:'客户全称',prop:'GWAKL004', width: 150}
                                            ]
                                        },
                                        cb:function (data) {
                                            vue.isearch.fields.GWCA006 = data.GWAK001;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择客户',
                                        area:['600px', '465px']
                                    }
                                });
                            }else if(field == 'GWCA005'){//合同编号开窗
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method:'q_gwca005',
                                            columnList: [
                                                {label: '合同编号', prop: 'GWCA005', width: '150'},
                                                {label: '合同签订组织', prop: 'GWCAMLEGAL', width: '150'}
                                            ],
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCA005 = data.GWCA005;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择合同编号',
                                        area: ['600px', '465px']
                                    }
                                });
                            }else if(field == 'GWCAORIG'){
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'q_sysorg_id',
                                            columnList: [
                                                {label: '部门ID', prop: 'ID', width: '150'},
                                                {label: '部门名称', prop: 'NAME', width: '150'}
                                            ],
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCAORIG = data.ID;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择部门',
                                        area: ['600px', '465px']
                                    }
                                });
                            }else if(field == 'GWCAORIU'){
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method: 'q_sysuser_id',
                                            columnList: [{label: 'ID', prop: 'ID', width: '150'},
                                                {label: '名称', prop: 'NAME', width: '150'}]
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWCAORIU = data.ID;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择业务员',
                                        area: ['600px', '465px']
                                    }
                                });
                            }
                        }
                    },
                    watch:{
                        'isearch.fields.GWCA036':function(newValue,oldValue){
                            if(newValue != null && newValue.length == 2){
                                this.isearch.fields.GWCA036_START = newValue[0];
                                this.isearch.fields.GWCA036_END = newValue[1];
                            }else{
                                this.isearch.fields.GWCA036_START = '';
                                this.isearch.fields.GWCA036_END = '';
                            }
                        }
                    },
                    created: function(){
                        //console.log(vueData);
                    }
                }]
            });

            self.initTable();
        },
        _lazy: function () {
            this._super();
            layui.use(['table'], function () {
                element = layui.element;
            });
        }
    });

    return new gwcq001();

});
